package com.ysd.lis.controller.lab;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.annotation.MainInfoLog;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.dto.lab.MaininfoDto;
import com.ysd.lis.entity.PubEmployee;
import com.ysd.lis.entity.SysInterface;
import com.ysd.lis.entity.SysOrgDepartment;
import com.ysd.lis.entity.SysUser;
import com.ysd.lis.entity.lab.*;
import com.ysd.lis.mapper.lab.*;
import com.ysd.lis.mapper.sys.SysInterfaceMapper;
import com.ysd.lis.request.*;
import com.ysd.lis.request.lab.*;
import com.ysd.lis.service.SysParamValueService;
import com.ysd.lis.service.bak.LabMaininfoBakService;
import com.ysd.lis.service.lab.*;
import com.ysd.lis.service.lab.impl.LabMainInfoServiceBakImpl;
import com.ysd.util.PinYinUtil;
import com.ysd.util.RedisUserManager;
import com.ysd.util.ToolsUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Cfz
 * @since 2023-12-26
 */
@RestController
@RequestMapping("/lab/maininfo")
public class LabMaininfoController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(LabMaininfoController.class);


    @Autowired
    LabMaininfoService labMaininfoService;
    @Autowired
    LabMaininfoMapper labMaininfoMapper;

    @Autowired
    LabMaininfoBakService labMaininfoBakService;
    @Autowired
    LabRptGroupMapper labRptGroupMapper;
    @Autowired
    LabMainInfoServiceBakImpl labMainInfoServiceBak;
    @Autowired
    SysInterfaceMapper sysInterfaceMapper;
    @Autowired
    LabMaininfoBacService labMaininfoBacService;
    @Autowired
    LabRptresultMapper labRptresultMapper;
    @Autowired
    LabRptmainMapper labRptmainMapper;
    @Autowired
    LabTemplateService labTemplateService;
    @Autowired
    LabRptresultService labRptresultService;
    @Autowired
    LabTemplateMapper labTemplateMapper;
    @Autowired
    LabReqMainService labReqMainService;

    @Autowired
    SysParamValueService sysParamValueService;


    @ApiOperation("更新拼音")
    @GetMapping("/updatePyName")
    public Result updatePyName() {
        //改修改
        LambdaQueryWrapper<LabMaininfo> lambdaQueryWrappers = new LambdaQueryWrapper<>();
        lambdaQueryWrappers.eq(LabMaininfo::getDelFlag, 0);
        lambdaQueryWrappers.isNotNull(LabMaininfo::getPatNa);
        lambdaQueryWrappers.and(item -> item.isNull(LabMaininfo::getPatPyName).or().eq(LabMaininfo::getPatPyName, ""));
        List<LabMaininfo> list = labMaininfoService.list(lambdaQueryWrappers);
        if (CollectionUtil.isNotEmpty(list)) {
            for (LabMaininfo labMaininfo : list) {
                if (StringUtils.isNotBlank(labMaininfo.getPatNa())) {
                    String apply = PinYinUtil.firstPinYinFun.apply(labMaininfo.getPatNa());
                    labMaininfo.setPatPyName(apply);
                }
            }
        }
        boolean b = labMaininfoService.updateBatchById(list);

        return null;
    }

    @ApiOperation("获取标本信息")
    @GetMapping("/findLabMaininfo")
    public Result findLabMaininfo(LabMaininfo labMaininfo) {
        return labMaininfoService.findLabMaininfo(labMaininfo);
    }

    @ApiOperation("模板应用点下一个的时候自动添加模板数据")
    @PostMapping("/addTempleteResult")
    public Result addTempleteResult(@RequestBody LabMaininfo labMaininfo) {
        LambdaQueryWrapper<LabMaininfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LabMaininfo::getRptGroup, labMaininfo.getRptGroup())
                .eq(LabMaininfo::getSampleda, labMaininfo.getSampleda())
                .eq(LabMaininfo::getSampleNo, labMaininfo.getSampleNo())
                .eq(LabMaininfo::getDelFlag, 0);
        List<LabMaininfo> list = labMaininfoService.list(lambdaQueryWrapper);

        LambdaQueryWrapper<LabRptresult> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper1.eq(LabRptresult::getRptGroup, labMaininfo.getRptGroup())
                .eq(LabRptresult::getSampleNo, labMaininfo.getSampleNo())
                .eq(LabRptresult::getSampleda, labMaininfo.getSampleda())
                .eq(LabRptresult::getDelFlag, 0);
        List<LabRptresult> list1 = labRptresultMapper.selectList(lambdaQueryWrapper1);
        if (CollectionUtil.isEmpty(list1)) {
            if (CollectionUtil.isNotEmpty(list)) {
                LambdaQueryWrapper<LabTemplate> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(LabTemplate::getDelFlag, 0).eq(LabTemplate::getRptGroup, labMaininfo.getRptGroup()).eq(LabTemplate::getIsAutoApply, "1");
                List<LabTemplate> labTemplates = labTemplateMapper.selectList(queryWrapper);
                if (CollectionUtil.isNotEmpty(labTemplates)) {
                    //插入模板数据
                    TemplateParams tmpParam = new TemplateParams();
                    tmpParam.setMaininfoId(list.get(0).getId());
                    tmpParam.setRptGroup(list.get(0).getRptGroup());
                    tmpParam.setSampleda(list.get(0).getSampleda());
                    tmpParam.setSampleNo(list.get(0).getSampleNo());
                    tmpParam.setReqNo(list.get(0).getReqNo());
                    labTemplateService.batchInsertDefItemDictAndTemplate(tmpParam);
                    //重新计算检验结果
                    //labRptresultCalcService.reCalcReferRange1(labMaininfo);
                    new Thread(() -> {
                        labRptresultService.reCalcRptRssults(list.get(0));
                    }).start();
                }
            }
        }
        return Result.succ(1, "成功", "");
    }


    @ApiOperation("微生物获取检验信息")
    @GetMapping("/findLabMaininfoBac")
    public Result findLabMaininfoBac(LabMaininfo labMaininfo) {
        return labMaininfoService.findLabMaininfoBac(labMaininfo);
    }

    @ApiOperation("根据条码号获取标本信息")
    @GetMapping("/findLabMaininfoByReqNo")
    public Result findLabMaininfoByReqNo(LabMaininfo labMaininfo) throws JsonProcessingException {
        LambdaQueryWrapper<LabMaininfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LabMaininfo::getReqNo, labMaininfo.getReqNo()).eq(LabMaininfo::getDelFlag, 0);
        //其他报告单元上机是否提示
        SysParamParam sysp2 = new SysParamParam();
        sysp2.setParamCode("bgdyxtcs");
        sysp2.setField("qtbgdysjbts");
        sysp2.setClassifyCode(labMaininfo.getRptGroup());
        List<SysParamFieldValueDto> kcflrdstndtmLst = sysParamValueService.findSysParamFieldAndValueListByCode(sysp2);
        String qtbgdysjsfts = kcflrdstndtmLst.size() <= 0 ? "" : kcflrdstndtmLst.get(0).getValue();
        if (StringUtils.isNotBlank(qtbgdysjsfts) && qtbgdysjsfts.equals("1")) {
            lambdaQueryWrapper.eq(LabMaininfo::getRptGroup, labMaininfo.getRptGroup());
        }


        List<LabMaininfo> list = labMaininfoService.list(lambdaQueryWrapper);
        list.forEach(a -> {
            LambdaQueryWrapper<LabRptGroup> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
            lambdaQueryWrapper1.eq(LabRptGroup::getRptGroup, a.getRptGroup()).eq(LabRptGroup::getDelFlag, 0);
            List<LabRptGroup> labRptGroups = labRptGroupMapper.selectList(lambdaQueryWrapper1);
            if (CollectionUtil.isNotEmpty(labRptGroups)) {
                a.setRptGroupNa(labRptGroups.get(0).getRptGroupName());
            }
        });
        return Result.succ(1, "查询成功", list);
    }

    @ApiOperation("分页查询检验主记录")
    @PostMapping("/findLabMaininfoPageList")
    public Result findLabMaininfoPageList(@RequestBody LabMaininfoPageDto maininfoPageDto) {
        return labMaininfoBacService.findLabMaininfoPageList(maininfoPageDto);
    }

    @ApiOperation("批次删除查询")
    @PostMapping("/searchLabMaininfoList")
    public Result searchLabMaininfoList(@RequestBody LabMaininfoPageDto maininfoPageDto) {
        return labMaininfoBakService.searchLabMaininfoList(maininfoPageDto);
    }

    @ApiOperation("批次删除查询")
    @PostMapping("/searchMaininfoListByItem")
    public Result searchMaininfoListByItem(@RequestBody LabMaininfoPageDto maininfoPageDto) {
        return labMaininfoBakService.searchMaininfoListByItem(maininfoPageDto);
    }

    @ApiOperation("工作统计查询")
    @PostMapping("/workSearchMaininfoList")
    public Result workSearchMaininfoList(@RequestBody LabMaininfoPageDto maininfoPageDto) throws SQLException {
        return labMaininfoBakService.workSearchMaininfoList(maininfoPageDto);
    }

    @ApiOperation("工作统计查询明细")
    @PostMapping("/workSearchResultList")
    public Result workSearchResultList(@RequestBody LabMaininfoPageDto maininfoPageDto) {
        return labMaininfoBakService.workSearchResultList(maininfoPageDto);
    }


    @ApiOperation("批次删除")
    @PostMapping("/removeLabMaininfoList")
    public Result removeLabMaininfoList(@RequestBody MaininfoDto maininfoDto) {
        return labMaininfoBakService.removeLabMaininfoList(maininfoDto);
    }


    @ApiOperation("his查看报告")
    @PostMapping("/findLabMaininfoByHis")
    public Result findLabMaininfoByHis(@RequestBody LabMaininfoPageDto maininfoPageDto) throws JsonProcessingException {


        /*验证系统参数，查看初审报告*/
        SysParamParam sysp1 = new SysParamParam();
        sysp1.setParamCode("xtxxcs");
        sysp1.setField("hisckbgsfcxcs");
        List<SysParamFieldValueDto> r1 = sysParamValueService.findSysParamFieldAndValueListByCode(sysp1);
        if (!r1.isEmpty()) {
            if (r1.get(0).getValue().equals("1")) {
                return labMaininfoBacService.findLabMaininfoByHis(maininfoPageDto);
            }
        }
        //获取系统参数 判断是否查询初审数据
        return labMaininfoBacService.findLabMaininfoPageList(maininfoPageDto);
    }

    @ApiOperation("查询检验主记录(历史数据)")
    @PostMapping("/findHisStoryLabMaininfoList")
    public Result findHisStoryLabMaininfoList(@RequestBody LabMaininfoPageDto maininfoPageDto) {
        return labMaininfoBakService.findHisStoryLabMaininfoList(maininfoPageDto);
    }


    @ApiOperation("扫码上机")
    @PostMapping("/insertMaininfoByReqNo")
    @MainInfoLog(operationType = OperationType.INSERT, module = "检验报告", content = "新增标本信息", businessName = "mainInfo")
    public Result insertMaininfoByReqNo(@RequestBody AddLabMaininfo labReqMain) throws JsonProcessingException {
        return labMaininfoService.insertMaininfoByReqNo(labReqMain);
    }

    @ApiOperation("不合格标本扫码")
    @PostMapping("/insertMaininfoBySpecimen")
    @MainInfoLog(operationType = OperationType.INSERT, module = "检验报告", content = "不合格标本扫码", businessName = "mainInfo")
    public Result insertMaininfoBySpecimen(@RequestBody AddLabMaininfo labReqMain) throws JsonProcessingException {
        return labMaininfoService.insertMaininfoBySpecimen(labReqMain);
    }


    @ApiOperation("上机")
    @MainInfoLog(operationType = OperationType.UPDATE, module = "检验报告", content = "修改标本信息", businessName = "mainInfo")
    @PostMapping("/updateMaininfo")
    public Result updateMaininfo(@RequestBody LabMaininfoCreateOrUpdateDto input) throws JsonProcessingException {
        return labMaininfoService.updateMaininfo(input);
    }

    @ApiOperation("上机")
    @PostMapping("/updateMaininfoByScanReqNo")
    public Result updateMaininfoByScanReqNo(@RequestBody LabMaininfoCreateOrUpdateDto input) throws JsonProcessingException {
        return labMaininfoService.updateMaininfoByScanReqNo(input);
    }

    @ApiOperation("删除标本")
    @PostMapping("/deleteMaininfoById")
    @MainInfoLog(operationType = OperationType.DELETE, module = "检验报告", content = "删除标本", businessName = "mainInfo")
    public Result deleteMaininfoById(@RequestBody LabMaininfo labMaininfo) {
        return labMaininfoService.deleteMaininfoById(labMaininfo);
    }

    @ApiOperation("获取当前标本的结果信息")
    @GetMapping("/findRptResultByLabMaininfo")
    public Result findRptResultByLabMaininfo(String id) {
        return labMaininfoService.findRptResultByLabMaininfo(id);
    }

    @ApiOperation("获取当前标本的结果信息(历史数据)")
    @GetMapping("/findHisStoryRptResultByLabMaininfo")
    public Result findHisStoryRptResultByLabMaininfo(LabMaininfo labMaininfo) {
        return labMaininfoBakService.findHisStoryRptResultByLabMaininfo(labMaininfo);
    }

    @ApiOperation("根据REQ_NO获取当前标本的结果信息")
    @GetMapping("/findRptResultByLabMainReqNo")
    public Result findRptResultByLabMainReqNo(@RequestParam(value = "reqNo") String reqNo, @RequestParam(value = "rptGroup") String rptGroup) {
        return labMaininfoService.findRptResultByLabMainReqNo(reqNo, rptGroup);
    }

    @ApiOperation("获取当前标本的结果信息开始加载")
    @GetMapping("/findRptResultByLabMaininfoMouted")
    public Result findRptResultByLabMaininfoMouted(String id) {
        return labMainInfoServiceBak.findRptResultByLabMaininfoMouted(id);
    }


    @ApiOperation("获取当前标本的历史结果信息")
    @GetMapping("/findHistoryResultByLabMaininfo")
    public Result findHistoryResultByLabMaininfo(String id) {
        return labMainInfoServiceBak.findHistoryResultByLabMaininfo1(id);
    }


    @ApiOperation("获取审批信息")
    @PostMapping("/findReviewedResutByLabMaininfo")
    public Result findReviewedResutByLabMaininfo(@RequestBody ReviewedMaininfoDto reviewedMaininfoDto) {
        return labMaininfoService.findReviewedResutByLabMaininfo(reviewedMaininfoDto);
    }

    @ApiOperation("获取检验结果信息")
    @PostMapping("/findInspectResultList")
    public Result findInspectResultList(@RequestBody ReviewedMaininfoDto reviewedMaininfoDto) {
        return labMaininfoService.findInspectResultList(reviewedMaininfoDto);
    }

    @ApiOperation("批量更新检验结果")
    @PostMapping("/saveTestResultBatch")
    public Result saveTestResultBatch(@RequestBody UpdateTestResultParams updateTestResultParams) {
        return labMaininfoService.saveTestResultBatch(updateTestResultParams);
    }

    @ApiOperation("修改审批状态")
    @PostMapping("/updateIsChkBySampleNos")
    public Result updateIsChkBySampleNos(@RequestBody UpdateIsChkDto updateIsChkDto) {
        return labMaininfoService.updateIsChkBySampleNos(updateIsChkDto);
    }

    @ApiOperation("点击预览")
    @PostMapping("/previewRpt")
    public Result previewRpt(@RequestBody LabMaininfo labMaininfo) {
        return labMaininfoService.previewRpt(labMaininfo, 2);
    }

    @ApiOperation("his查询报告获取结果回顾")
    @GetMapping("/findResultReviewByPatNo")
    public Result findResultReviewByPatBo(LabMaininfoParam labMaininfo) {
        return labMainInfoServiceBak.findResultReviewByPatNo(labMaininfo);
    }

    @ApiOperation("his查询报告获取结果回顾病区")
    @GetMapping("/findResultReviewByPatNoArea")
    public Result findResultReviewByPatNoArea(LabMaininfoParam labMaininfo) {
        return labMainInfoServiceBak.findResultReviewByPatNoArea(labMaininfo);
    }

    @ApiOperation("判断是否有历史结果")
    @GetMapping("/findResultReviewHistory")
    public Result findResultReviewHistory(LabMaininfoParam labMaininfo) {
        return labMainInfoServiceBak.findResultReviewHistory(labMaininfo);
    }

    @ApiOperation("判断是否有图文报告历史结果")
    @GetMapping("/findResultRptReviewHistory")
    public Result findResultRptReviewHistory(LabMaininfoParam labMaininfo) {
        return labMainInfoServiceBak.findResultRptReviewHistory(labMaininfo);
    }


    @ApiOperation("更改完审核人、检验人后更新上机记录数据")
    @PostMapping("/updateTestChkDoctorAfterAuth")
    @MainInfoLog(operationType = OperationType.AUDIT, module = "检验报告", content = "更改完审核人、检验人后更新上机记录数据", businessName = "rptResult")
    public Result updateTestChkDoctorAfterAuth(@RequestBody UptMainInfoTextChkDoctorDto input) throws JsonProcessingException {
        return labMaininfoService.updateTestChkDoctorAfterAuth(input);
    }

    @ApiOperation("审核前判断申请项目是染色项目,染色结果是否存在数据(浏阳肌理)")
    @GetMapping("/judgeStainingResult")
    public Result judgeStainingResult(LabMaininfoParam labMaininfo) {
        return labMainInfoServiceBak.judgeStainingResult(labMaininfo);
    }

    @ApiOperation("更改完审核人、检验人后更新上机记录数据（细菌）")
    @PostMapping("/updateBacTestChkDoctorAfterAuth")
    @MainInfoLog(operationType = OperationType.AUDIT, module = "细菌检验", content = "更改完审核人、检验人后更新上机记录数据", businessName = "rptResult")
    public Result updateBacTestChkDoctorAfterAuth(@RequestBody UptMainInfoTextChkDoctorDto input) throws JsonProcessingException {
        Result result = labMaininfoService.updateBacTestChkDoctorAfterAuth(input);
        return result;
    }

    @ApiOperation("取消审核")
    @PostMapping("/unChkMainInfo")
    @MainInfoLog(operationType = OperationType.UN_AUDIT, module = "检验报告", content = "取消审核", businessName = "rptResult")
    public Result unChkMainInfo(@RequestBody LabMaininfo labMaininfo) throws JsonProcessingException {
        return labMaininfoService.unChkMainInfo(labMaininfo);
    }

    @ApiOperation("取消审核")
    @PostMapping("/unChkBacMainInfo")
    @MainInfoLog(operationType = OperationType.UN_AUDIT, module = "细菌检验", content = "取消审核", businessName = "rptResult")
    public Result unChkBacMainInfo(@RequestBody LabMaininfo labMaininfo) throws JsonProcessingException {
        Result result = labMaininfoService.unChkBacMainInfo(labMaininfo);

        if (!BeanUtil.isEmpty(labMaininfo.getIsChk()) && labMaininfo.getIsChk().equals(new BigDecimal(2))) {
            //假删掉报告单
            LambdaQueryWrapper<LabRptmain> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper
                    .eq(LabRptmain::getRptGroup, labMaininfo.getRptGroup())
                    .eq(LabRptmain::getSampleda, labMaininfo.getSampleda())
                    .eq(LabRptmain::getSampleNo, labMaininfo.getSampleNo())
                    .eq(LabRptmain::getDelFlag, 0);
            labRptmainMapper.delete(lambdaQueryWrapper);
            //调用发送微生物报告接口
            SysUser sysUser = RedisUserManager.getUser();
            LambdaQueryWrapper<SysInterface> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysInterface::getDelFlag, 0);
            wrapper.eq(SysInterface::getIsEnable, 1);
            wrapper.eq(SysInterface::getOrgId, sysUser.getOrgId());
            List<SysInterface> sysInterfaces = sysInterfaceMapper.selectList(wrapper);
            List<String> collect = sysInterfaces.stream().filter(o -> Objects.nonNull(o) && StringUtils.isNotBlank(o.getInterfaceUrl())).map(SysInterface::getInterfaceUrl).distinct().collect(Collectors.toList());
            //标本消申
            if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(collect)) {
                /*发布报告相关*/
                for (String webUrl : collect) {
                    //消审走报告发布传delete
//                    Map releaseReportMap = new HashMap();
//                    String releaseReport = webUrl + "/public/cancleWswReport";
//                    releaseReportMap.put("orgId", sysUser.getOrgId());
//                    releaseReportMap.put("mainInfoId", labMaininfo.getId());
//                    HttpUtil.createPost(releaseReport).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(releaseReportMap)).contentType("application/json").execute().body();

                    //消审走报告发布传delete
                    Map releaseReportMap1 = new HashMap();
                    String releaseReport1 = webUrl + "/public/releaseWswReport";
                    releaseReportMap1.put("orgId", labMaininfo.getOrgId());
                    releaseReportMap1.put("mainInfoId", labMaininfo.getId());
                    releaseReportMap1.put("deleteFlag", "1");
                    String release = HttpUtil.createPost(releaseReport1).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(releaseReportMap1)).contentType("application/json").execute().body();
                    logger.info("发布报告返回值:\n" + release);
                    try {
                        JSONObject releaseObject = new JSONObject(release);
                        JSONObject releaseStatus = releaseObject.getJSONObject("status");
                        String releaseCode = releaseStatus.get("code").toString();
                        if (!"400".equals(releaseCode)) {
                            String updateUrl = webUrl + "/public/updateReportStatus";
                            Map<String, Object> updateMap = new HashMap<>();
                            updateMap.put("status", "99");//消审
                            updateMap.put("reqNo", labMaininfo.getReqNo());
                            updateMap.put("patType", labMaininfo.getPatType());
                            updateMap.put("chkDoctor", labMaininfo.getChkDoctor());
                            updateMap.put("testDoctor", labMaininfo.getTestDoctor());
                            updateMap.put("patType", labMaininfo.getPatType());
                            updateMap.put("samplingTime", BeanUtil.isEmpty(labMaininfo.getSamplingTime()) ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(labMaininfo.getSamplingTime()));
                            updateMap.put("signTime", BeanUtil.isEmpty(labMaininfo.getSignTime()) ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(labMaininfo.getSignTime()));
                            updateMap.put("operateTime", BeanUtil.isEmpty(labMaininfo.getTestTime()) ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(labMaininfo.getTestTime()));
                            updateMap.put("reportTime", BeanUtil.isEmpty(labMaininfo.getChkTime()) ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(labMaininfo.getChkTime()));
                            updateMap.put("orgId", labMaininfo.getOrgId());
                            updateMap.put("username", sysUser.getUsername());
                            updateMap.put("realname", sysUser.getRealname());
                            updateMap.put("id", labMaininfo.getId());
                            HttpUtil.createPost(updateUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                            //消审走报告发布需要撤销掉报告单(伊通需要)
                            Map releaseReportMap2 = new HashMap();
                            String zfReportUrl = webUrl + "/public/zfReleaseWswReport";
                            releaseReportMap2.put("orgId", labMaininfo.getOrgId());
                            releaseReportMap2.put("mainInfoId", labMaininfo.getId());
                            HttpUtil.createPost(zfReportUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(releaseReportMap2)).contentType("application/json").execute().body();
                        }
                    } catch (Exception e) {
                        logger.info("发布报告返回值:\n" + release);
                    }
//                    String releaseReportHL7 = webUrl + "/cancleReport";
//                    HttpUtil.createPost(releaseReportHL7).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(releaseReportMap)).contentType("application/json").execute().body();
                }
            }
        }
        return result;
    }

    @ApiOperation("批量取消审核")
    @PostMapping("/unChkMainInfoMany")
    @MainInfoLog(operationType = OperationType.UN_AUDIT, module = "检验报告", content = "批量取消审核", businessName = "rptResult")
    public Result unChkMainInfoMany(@RequestBody LabMainInfoBatchUnChk input) throws JsonProcessingException {
        return labMaininfoService.unChkMainInfoMany(input);
    }

    @ApiOperation("查询检验报告")
    @GetMapping("/findLabMainInfoList")
    public Result findLabMainInfoList(LabMainInfoDto mainInfoDto) {
        return labMaininfoService.findLabMainInfoList(mainInfoDto);
    }

    @ApiOperation("批量删除")
    @PostMapping("/labMainInfoBatchDelete")
    public Result LabMainInfoBatchDelete(@RequestBody LabMainInfoBatchDelete input) {
        return labMaininfoService.LabMainInfoBatchDelete(input);
    }

    @ApiOperation("批量审核检验记录")
    @PostMapping("/labMainInfoBatchChk")
    @MainInfoLog(operationType = OperationType.AUDIT, module = "检验报告", content = "批量取消审核", businessName = "rptResult")
    public Result LabMainInfoBatchChk(@RequestBody LabMainInfoBatchChk input) throws JsonProcessingException {
        return labMaininfoService.LabMainInfoBatchChk(input);
    }


    @ApiOperation("批量审核检验记录（挨个处理）")
    @PostMapping("/batchChkLabMaininfo")
    @MainInfoLog(operationType = OperationType.AUDIT, module = "检验报告", content = "批量审核检验记录（挨个处理）", businessName = "rptResult")
    public Result batchChkLabMaininfo(@RequestBody BachChkBatchChk input) throws JsonProcessingException {
        return labMaininfoService.batchChkLabMaininfo(input);
    }

    @ApiOperation("批次打印页面-批量打印")
    @PostMapping("/bachChkBatchPrint")
    public Result bachChkBatchPrint(@RequestBody BachChkBatchChk bachChkBatchChk) throws JsonProcessingException {
        return labMaininfoService.bachChkBatchPrint(bachChkBatchChk);
    }

    @ApiOperation("批量打印")
    @PostMapping("/labMainInfoBatchPrint")
    public Result LabMainInfoBatchPrint(@RequestBody LabMainInfoBatchPrint input) {
        return labMaininfoService.LabMainInfoBatchPrint(input);
    }

    @ApiOperation("合并打印")
    @PostMapping("/labMainInfoMergePrint")
    public Result labMainInfoMergePrint(@RequestBody BatchPrintDto batchPrintDto) throws JsonProcessingException {
        return labMaininfoService.labMainInfoMergePrint(batchPrintDto);
    }

    @ApiOperation("报告查询批量打印报告")
    @PostMapping("/printRptBatch")
    public Result PrintRptBatch(@RequestBody List<LabMaininfo> labMaininfos) {
        return labMaininfoService.PrintRptBatch(labMaininfos);
    }

    @ApiOperation("报告查询批量预览报告")
    @PostMapping("/viewRptBatch")
    public Result viewRptBatch(@RequestBody List<LabMaininfo> labMaininfos) {
        return labMainInfoServiceBak.ViewRptBatch(labMaininfos);
    }

    @ApiOperation("打印检验记录")
    @PostMapping("/LabMainInfoPrint")
    @MainInfoLog(operationType = OperationType.PRINT, module = "检验报告", content = "打印检验记录", businessName = "rptResult")
    public Result LabMainInfoPrint(@RequestBody LabMaininfo labMaininfo) {
        return labMaininfoService.LabMainInfoPrint(labMaininfo);
    }

    //自助机调用
    @ApiOperation("查询检验报告")
    @PostMapping("/findLabMainInfos")
    public Result findLabMainInfos(@RequestBody LabMainInfoDtos mainInfoDto) {
        return labMaininfoService.findLabMainInfos(mainInfoDto);
    }

    //自助机调用
    @ApiOperation("阳性报表")
    @PostMapping("/getPositiveReports")
    public Result getPositiveReports(@RequestBody GetPositiveReportDto input) {
        return labMaininfoService.getPositiveReports(input);
    }

    @ApiOperation("自助机打印成功后更新自助机打印状态")
    @PostMapping("/updateMainInfoPrintStatus")
    public Result updateMainInfoPrintStatus(@RequestBody UpdateMaininfoAfterAutoPrinted input) {
        return labMaininfoService.updateMainInfoPrintStatus(input);
    }

    //综合统计(检验项目)
    @ApiOperation("综合统计(检验项目)")
    @PostMapping("/testQueryInfo")
    public Result testQueryInfo(@RequestBody TestQueryDto testQueryDto) {
        return labMaininfoService.testQueryInfo(testQueryDto);
    }

    //综合统计(检验项目)
    @ApiOperation("综合统计(申请项目)")
    @PostMapping("/reqQueryInfo")
    public Result reqQueryInfo(@RequestBody TestQueryDto testQueryDto) {
        return labMaininfoService.reqQueryInfo(testQueryDto);
    }

    //综合统计(检验项目)
    @ApiOperation("标本合并")
    @PostMapping("/mergeTestList")
    public Result mergeTestList(@RequestBody LabMainInfoMerge input) {
        return labMaininfoService.mergeTestList(input);
    }


    @ApiOperation("批量更新")
    @PostMapping("/batchUpdateRptResultByTemplate")
    public Result batchUpdateRptResultByTemplate(@RequestBody LabTemResultParam param) {
        return labMaininfoService.batchUpdateRptResultByTemplate(param);
    }

    @ApiOperation("调用接口平台通知his退费")
    @PostMapping("/noticeHisRefound")
    public Result noticeHisRefound(@RequestBody LabMaininfo labMaininfo) {
        try {
            SysUser sysUser = RedisUserManager.getUser();
            LabMaininfo byId = labMaininfoService.getById(labMaininfo.getId());

            if (BeanUtil.isNotEmpty(byId)) {
                if (ToolsUtils.isNotEmpty(byId.getIsChk()) && byId.getIsChk().intValue() > 0) {
                    return Result.fail("已审核不允许删除！");
                }
                /*
                 *  取消上机的时候 先查一下 有没有这个条码的其他上机记录，
                 * 如果有的话 弹窗列出所有的上机记录，然后可以勾选的把其他的mainfo的数据一块假删除，
                 * 然后改reqmain的STATE为70（标本签收）
                 */
                if (ToolsUtils.isNotEmpty(byId.getReqNo())) {
                    //查看是否有其他上机记录

                    MPJLambdaWrapper<LabMaininfo> queryWrapper = new MPJLambdaWrapper<>();
                    queryWrapper.selectAll(LabMaininfo.class);
                    queryWrapper.selectAs(LabSampleType::getSampleTypeName, LabMaininfo::getSampleTypeNa);
                    queryWrapper.selectAs(SysOrgDepartment::getName, LabMaininfo::getReqDeptNa);
                    queryWrapper.selectAs("req", PubEmployee::getName, LabMaininfo::getReqDoctorNa);
                    queryWrapper.selectAs("test", SysUser::getRealname, LabMaininfo::getTestDoctorNa);
                    queryWrapper.selectAs("chk", SysUser::getRealname, LabMaininfo::getChkDoctorNa);
                    queryWrapper.selectAs("rechk", SysUser::getRealname, LabMaininfo::getReChkDoctorNa);
                    queryWrapper.selectAs("prt", SysUser::getRealname, LabMaininfo::getPrintDoctorNa);
                    queryWrapper.selectAs("sampl", SysUser::getRealname, LabMaininfo::getSamplingDoctorNa);
                    queryWrapper.selectAs("signer", SysUser::getRealname, LabMaininfo::getSignerDoctorNa);
                    queryWrapper.selectAs("rptgrp", LabRptGroup::getRptGroupName, LabMaininfo::getRptGroupNa);
                    queryWrapper.selectAs("reqm", LabReqMain::getId, LabMaininfo::getReqMainId);
                    queryWrapper.leftJoin(LabSampleType.class, p -> p.eq(LabSampleType::getSampleTypeCode, LabMaininfo::getSampleType).eq(LabSampleType::getDelFlag, 0));
                    queryWrapper.leftJoin(SysOrgDepartment.class, p -> p.eq(SysOrgDepartment::getCode, LabMaininfo::getReqDept).eq(SysOrgDepartment::getDelFlag, 0));
                    queryWrapper.leftJoin(PubEmployee.class, "req", p -> p.eq(PubEmployee::getCode, LabMaininfo::getReqDoctor).eq(PubEmployee::getDelFlag, 0));
                    queryWrapper.leftJoin(SysUser.class, "test", p -> p.eq(SysUser::getUsername, LabMaininfo::getTestDoctor).eq(SysUser::getDelFlag, 0).isNotNull(SysUser::getUsername).ne(SysUser::getUsername, ""));
                    queryWrapper.leftJoin(SysUser.class, "chk", p -> p.eq(SysUser::getUsername, LabMaininfo::getChkDoctor).eq(SysUser::getDelFlag, 0).isNotNull(SysUser::getUsername).ne(SysUser::getUsername, ""));
                    queryWrapper.leftJoin(SysUser.class, "rechk", p -> p.eq(SysUser::getUsername, LabMaininfo::getReChkDoctor).eq(SysUser::getDelFlag, 0).isNotNull(SysUser::getUsername).ne(SysUser::getUsername, ""));
                    queryWrapper.leftJoin(SysUser.class, "prt", p -> p.eq(SysUser::getUsername, LabMaininfo::getPrintDoctor).eq(SysUser::getDelFlag, 0).isNotNull(SysUser::getUsername).ne(SysUser::getUsername, ""));
                    queryWrapper.leftJoin(SysUser.class, "sampl", p -> p.eq(SysUser::getUsername, LabMaininfo::getSamplingDoctor).eq(SysUser::getDelFlag, 0).isNotNull(SysUser::getUsername).ne(SysUser::getUsername, ""));
                    queryWrapper.leftJoin(SysUser.class, "signer", p -> p.eq(SysUser::getUsername, LabMaininfo::getSignerDoctor).eq(SysUser::getDelFlag, 0).isNotNull(SysUser::getUsername).ne(SysUser::getUsername, ""));
                    queryWrapper.leftJoin(LabRptGroup.class, "rptgrp", p -> p.eq(LabRptGroup::getRptGroup, LabMaininfo::getRptGroup).eq(LabRptGroup::getDelFlag, 0));
                    queryWrapper.leftJoin(LabReqMain.class, "reqm", p -> p.eq(LabReqMain::getReqNo, LabMaininfo::getReqNo).eq(LabReqMain::getDelFlag, 0));


                    queryWrapper.eq(LabMaininfo::getReqNo, byId.getReqNo())
                            .eq(LabMaininfo::getDelFlag, 0);
                    //.ne(LabMaininfo::getId,byId.getId());
                    List<LabMaininfo> maininfoList = labMaininfoService.list(queryWrapper);
                    List<LabMaininfo> list = maininfoList.stream().filter(a -> !a.getId().equals(byId.getId())).collect(Collectors.toList());


                    if (ToolsUtils.isEmpty(list)) {

                        labMaininfoBacService.cancelReqMainAndDetail(byId);
                    } else {
                        return Result.succ(100, "有其他上机记录！", maininfoList);
                    }

                }


                //刪除上机记录
                labMaininfoService.deleteMaininfoById(byId);

                LambdaQueryWrapper<SysInterface> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(SysInterface::getDelFlag, 0);
                wrapper.eq(SysInterface::getIsEnable, 1);
                List<SysInterface> sysInterfaces = sysInterfaceMapper.selectList(wrapper);
                List<String> collect = sysInterfaces.stream().filter(o -> Objects.nonNull(o) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(o.getInterfaceUrl())).map(SysInterface::getInterfaceUrl).distinct().collect(Collectors.toList());
                if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(collect)) {
                    for (String webUrl : collect) {
                        if (!"4".equals(byId.getPatType())) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.set("id", labMaininfo.getId());
                            jsonObject.set("username", sysUser.getUsername());
                            jsonObject.set("realname", sysUser.getRealname());
                            jsonObject.set("reqNo", labMaininfo.getReqNo());
                            //银丰医院退费接口
                            HttpUtil.createPost(webUrl + "/lisRestFul/noticeHisReFund").body(JSONUtil.toJsonStr(jsonObject)).contentType("application/json").execute().body();
                        }
                        //伊通更新医嘱状态接口调用多次
                        String updateUrl = webUrl + "/public/updateReportStatus";
                        Map<String, Object> updateMap = new HashMap<>();
                        updateMap.put("status", "97");
                        updateMap.put("reqNo", byId.getReqNo());
                        updateMap.put("patType", byId.getPatType());
                        updateMap.put("username", sysUser.getUsername());
                        updateMap.put("realname", sysUser.getRealname());
                        updateMap.put("orgId", sysUser.getOrgId());
                        updateMap.put("chargeType", "0");
                        HttpUtil.createPost(updateUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                        //调用执行医嘱确费接口
                        logger.info("%%%%%%%%%%%%%%%%%开始执行确费接口:" + JSONUtil.toJsonStr(byId));
                        if ("3".equals(byId.getPatType())) {
                            String yzqfUrl = webUrl + "/yzqf";
                            logger.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" + yzqfUrl);
                            String body = HttpUtil.createPost(yzqfUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                            logger.info(body);

//                            String updateUrlHl7 = webUrl + "/confimReFoundFee";
//                            HttpUtil.createPost(updateUrlHl7).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();


                        }
//                        String hl7Url = webUrl + "/public/cancleCheck";
//                        HttpUtil.createPost(hl7Url).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();

//                        String hl7Urlbarcode = webUrl + "/public/barcodeRecive";
//                        HttpUtil.createPost(hl7Urlbarcode).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
//

                        //东北双塔医院取消上机时退费（2025-03-20） 王柏刚
                        /*验证系统参数，无签收时间，禁止上机*/
                        SysParamParam sysp1 = new SysParamParam();
                        sysp1.setParamCode("xtxxcs");
                        sysp1.setField("qxsjreturnfeetohis");
                        List<SysParamFieldValueDto> r1 = sysParamValueService.findSysParamFieldAndValueListByCode(sysp1);
                        if (!r1.isEmpty()) {
                            if (r1.get(0).getValue().equals("1")) {
                                String returnFeeUrl = webUrl + "/public/barcodeDelReturnFee";
                                String update11 = HttpUtil.createPost(returnFeeUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                                LambdaUpdateWrapper<LabReqMain> lambdaQueryWrapper222 = new LambdaUpdateWrapper<>();
                                lambdaQueryWrapper222.eq(LabReqMain::getReqNo, byId.getReqNo()).eq(LabReqMain::getDelFlag, 0)
                                .set(LabReqMain::getIsCancel,1);
                                labReqMainService.update(null, lambdaQueryWrapper222);
                            }
                        }
                    }
                }
                return Result.succ(1, "取消上机成功", "");
            }
        } catch (Exception e) {
            logger.info("通知his退费接口异常，请核实！");
            e.printStackTrace();
        }
        return Result.fail("接口管理平台异常,请检查");
    }

    @ApiOperation("调用接口平台通知his退费")
    @PostMapping("/noticeHisRefoundList")
    public Result noticeHisRefoundList(@RequestBody UptedLabMainInfo uptedLabMainInfo) {
        try {
            SysUser sysUser = RedisUserManager.getUser();
            List<LabMaininfo> uptedLabMainInfos = uptedLabMainInfo.getUptedLabMainInfos();
            LabMaininfo curMainInfo = uptedLabMainInfo.getCurMainInfo();
            //取ID集合
            List<String> ids = uptedLabMainInfos.stream().map(LabMaininfo::getId).collect(Collectors.toList());
            List<LabMaininfo> maininfoListList = labMaininfoService.listByIds(ids);

            String reqNo = "";

            for (LabMaininfo byId : maininfoListList) {
                if (BeanUtil.isNotEmpty(byId)) {
                    if (ToolsUtils.isNotEmpty(byId.getIsChk()) && byId.getIsChk().intValue() > 0) {
                        return Result.fail("已审核不允许删除！");
                    }
                    reqNo = byId.getReqNo();
                    //只取消当前选中的reqmain
                    if (ToolsUtils.isNotEmpty(byId.getReqNo()) && ToolsUtils.isNotEmpty(curMainInfo) && curMainInfo.getId().equals(byId.getId())) {
                        labMaininfoBacService.cancelReqMainAndDetail(byId);
                    }

                    //刪除上机记录
                    labMaininfoService.deleteMaininfoById(byId);
                }
            }

            //uptedLabMainInfos 取出与curMainInfoid相同的一条数据
            LabMaininfo labMaininfo = uptedLabMainInfos.stream().filter(o -> Objects.nonNull(o) && curMainInfo.getId().equals(o.getId())).findFirst().orElse(null);
            LambdaQueryWrapper<SysInterface> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysInterface::getDelFlag, 0);
            wrapper.eq(SysInterface::getIsEnable, 1);
            List<SysInterface> sysInterfaces = sysInterfaceMapper.selectList(wrapper);
            List<String> collect = sysInterfaces.stream().filter(o -> Objects.nonNull(o) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(o.getInterfaceUrl())).map(SysInterface::getInterfaceUrl).distinct().collect(Collectors.toList());
            if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(collect)) {
                for (String webUrl : collect) {
                    if (!"4".equals(labMaininfo.getPatType())) {
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.set("id", labMaininfo.getId());
                        jsonObject.set("username", sysUser.getUsername());
                        jsonObject.set("realname", sysUser.getRealname());
                        jsonObject.set("reqNo", labMaininfo.getReqNo());
                        //银丰医院退费接口
                        HttpUtil.createPost(webUrl + "/lisRestFul/noticeHisReFund").body(JSONUtil.toJsonStr(jsonObject)).contentType("application/json").execute().body();
                    }
                    //伊通更新医嘱状态接口调用多次
                    String updateUrl = webUrl + "/public/updateReportStatus";
                    Map<String, Object> updateMap = new HashMap<>();
                    updateMap.put("status", "97");
                    updateMap.put("reqNo", labMaininfo.getReqNo());
                    updateMap.put("patType", labMaininfo.getPatType());
                    updateMap.put("username", sysUser.getUsername());
                    updateMap.put("realname", sysUser.getRealname());
                    updateMap.put("orgId", sysUser.getOrgId());
                    updateMap.put("chargeType", "0");
                    HttpUtil.createPost(updateUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                    //调用执行医嘱确费接口
                    logger.info("%%%%%%%%%%%%%%%%%开始执行确费接口:" + JSONUtil.toJsonStr(labMaininfo));
                    if ("3".equals(labMaininfo.getPatType())) {
                        String yzqfUrl = webUrl + "/yzqf";
                        logger.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" + yzqfUrl);
                        String body = HttpUtil.createPost(yzqfUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                        logger.info(body);

//                            String updateUrlHl7 = webUrl + "/confimReFoundFee";
//                            HttpUtil.createPost(updateUrlHl7).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();


                    }
//                        String hl7Url = webUrl + "/public/cancleCheck";
//                        HttpUtil.createPost(hl7Url).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();

//                        String hl7Urlbarcode = webUrl + "/public/barcodeRecive";
//                        HttpUtil.createPost(hl7Urlbarcode).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
//
                    //东北双塔医院取消上机时退费（2025-03-20） 王柏刚
                    /*验证系统参数，无签收时间，禁止上机*/
                    SysParamParam sysp1 = new SysParamParam();
                    sysp1.setParamCode("xtxxcs");
                    sysp1.setField("qxsjreturnfeetohis");
                    List<SysParamFieldValueDto> r1 = sysParamValueService.findSysParamFieldAndValueListByCode(sysp1);
                    if (!r1.isEmpty()) {
                        if (r1.get(0).getValue().equals("1")) {
                            String returnFeeUrl = webUrl + "/public/barcodeDelReturnFee";
                            String update11 = HttpUtil.createPost(returnFeeUrl).setConnectionTimeout(3000).body(JSONUtil.toJsonStr(updateMap)).contentType("application/json").execute().body();
                            LambdaUpdateWrapper<LabReqMain> lambdaQueryWrapper222 = new LambdaUpdateWrapper<>();
                            lambdaQueryWrapper222.eq(LabReqMain::getReqNo, reqNo).eq(LabReqMain::getDelFlag, 0)
                                    .set(LabReqMain::getIsCancel,1);
                            labReqMainService.update(null, lambdaQueryWrapper222);
                        }
                    }
                }
            }
            return Result.succ(1, "取消上机成功", "");


        } catch (Exception e) {
            logger.info("通知his退费接口异常，请核实！");
            e.printStackTrace();
        }
        return Result.fail("接口管理平台异常,请检查");
    }

    @ApiOperation("验证标本号是否已经创建")
    @GetMapping("/validateIsExistMainInfo")
    public Result validateIsExistMainInfo(LabMaininfo labMaininfo) {
        return labMaininfoService.validateIsExistMainInfo(labMaininfo);
    }

    @ApiOperation("扫码上机验证")
    @GetMapping("/validateByScanReqNo")
    public Result validateByScanReqNo(LabMaininfo labMaininfo) {
        return labMaininfoService.validateByScanReqNo(labMaininfo);
    }

    @ApiOperation("下载药物的excel导入模板")
    @PostMapping("/downloadReportExcel")
    public void downloadReportExcel(@RequestBody ReportExportExcelParam reportExportExcelParam, HttpServletResponse response) throws IOException {
        labMaininfoService.downloadReportExcel(reportExportExcelParam, response);
    }


    @ApiOperation("合并本人结果")
    @PostMapping("/resultMerge")
    public Result resultMerge(@RequestBody LabMaininfo labMaininfo) {
        return labMaininfoBakService.resultMerge(labMaininfo);
    }

    @ApiOperation("CA加密查询出结果信息")
    @GetMapping("/getRptresultByLabMainInfo")
    public Result getRptresultByLabMainInfo(LabRptresult labMaininfo) {
        Map returnMap = new HashMap();
        LambdaQueryWrapper<LabMaininfo> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper1.eq(LabMaininfo::getRptGroup, labMaininfo.getRptGroup())
                .eq(LabMaininfo::getSampleda, labMaininfo.getSampleda())
                .eq(LabMaininfo::getSampleNo, labMaininfo.getSampleNo())
                .eq(LabMaininfo::getDelFlag, 0);
        List<LabMaininfo> list1 = labMaininfoService.list(lambdaQueryWrapper1);
        if (CollectionUtil.isNotEmpty(list1)) {
            returnMap.put("labMainInfo", list1.get(0));
        }
        LambdaQueryWrapper<LabRptresult> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LabRptresult::getRptGroup, labMaininfo.getRptGroup())
                .eq(LabRptresult::getSampleda, labMaininfo.getSampleda())
                .eq(LabRptresult::getSampleNo, labMaininfo.getSampleNo())
                .eq(LabRptresult::getDelFlag, 0);
        List<LabRptresult> list = labRptresultMapper.selectList(lambdaQueryWrapper);
        returnMap.put("resultList", list);
        return Result.succ(1, "查询成功", returnMap);
    }

    //根据条码号获取病人的id和住院次数
    @ApiOperation("根据条码号获取病人的id和住院次数")
    @GetMapping("/getVisitNoByReqno")
    public Result getVisitNoByReqno(LabRptresult labMaininfo) {
        LambdaQueryWrapper<LabReqMain> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LabReqMain::getReqNo, labMaininfo.getReqNo())
                .eq(LabReqMain::getDelFlag, 0);
        List<LabReqMain> list = labReqMainService.list(lambdaQueryWrapper);
        return Result.succ(1, "查询成功", list);
    }
}
